import axios from "axios";
import store from './../vuex/store' // 应用vuex
import ElementUI from 'element-ui';
class GetDataFun {
  // 得到门票基础数据
  getTicketList() {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/ticketPurchasePC/queryTicketTypeList', {
          activityId: store.state.activityId,
          isPay: 'pay'
        })
        .then((res) => {
          if (res.data.success) {
            store.state.ticketList = [];
            store.state.ticketList = res.data.result;
            store.state.allTableData = res.data.result;
            for (let i = 0; i < store.state.ticketList.length; i++) {
              store.state.ticketList[i].link = `http:${i}`
            }
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "门票基础数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到价格组数据
  getPriceList(start = 1, limit = 10000) {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/ticketPurchasePC/queryTicketPrciceGroupListByProjectId', {
          projectId: store.state.activityId,
          start: start - 1,
          limit: limit,
        })
        .then((res) => {
          if (res.data.success) {
            store.state.priceList = [];
            store.state.priceList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "价格组数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到退款基础数据
  getrefundList(params) {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/ticketPurchasePC/queryTicketOrderByParam', params)
        .then((res) => {
          if (res.data.success) {
            store.state.refundList = [];
            store.state.refundList = res.data.result;
            // 开始时间进行排序
            for (let q = 0; q < store.state.refundList.length; q++) {
              for (
                let j = q + 1; j < store.state.refundList.length; j++
              ) {
                if (
                  store.state.refundList[q].createtime <
                  store.state.refundList[j].createtime
                ) {
                  let tmp = store.state.refundList[q];
                  store.state.refundList[
                    q
                  ] = store.state.refundList[j];
                  store.state.refundList[j] = tmp;
                }
              }
            }
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "订单数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到论坛管理表格数据
  getForuList(start = 1, limit = 10) {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/bbs/querybbs', {
          activityId: store.state.activityId,
          start: start - 1,
          limit: limit,
        })
        .then((res) => {
          if (res.data.success) {
            store.state.foruList = [];
            store.state.foruList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "论坛管理表格数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 查询协议
  getProtocolList(start = 1, limit = 10, typeId = 1) {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/agreeMent/queryAgreeMent', {
          typeId: typeId, //1 购票协议 2 登录协议 3 露脸协议
          activityId: store.state.activityId,
          start: start - 1,
          limit: limit,
          isPay: "pay"
        })
        .then((res) => {
          if (res.data.success) {
            store.state.protocolList = [];
            store.state.protocolList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "协议数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到分享列表
  getShareList(start = 1, limit = 10, channelName = "") {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/shareUrl/queryShareUrlByChannelName', {
          activityId: store.state.activityId,
          channelName: channelName,
          start: start - 1,
          limit: limit,
        })
        .then((res) => {
          if (res.data.success) {
            store.state.shareList = [];
            store.state.shareList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "分享列表数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到字段管理列表
  getFieldList(start = 1, limit = 10) {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.post('/api/isv/temp/queryModelList', {
          activityId: store.state.activityId,
          start: start - 1,
          limit: limit,
          isPay: "pay"
        })
        .then((res) => {
          if (res.data.success) {
            store.state.fieldList = [];
            store.state.fieldList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "字段管理列表数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };
  // 得到会务活动表格数据
  powerManageListFun() {
    return new Promise((resolve, reject) => {
      let obj = {
        state: "suess",
        val: "",
        data: ""
      }
      axios.get('/api/isv/activity/queryAll')
        .then((res) => {
          if (res.data.success) {
            store.state.powerManageList = [];
            store.state.powerManageList = res.data.result;
            resolve(obj);
          } else {
            obj.state = "war";
            ElementUI.Message.warning(res.data.errorMsg || "会务活动表格数据获取失败");
            reject(obj);
          }
        })
        .catch((error) => {
          obj.state = "err";
          ElementUI.Message.error("服务器出小差了");
          reject(obj);
        });
    });
  };

}

export default new GetDataFun();
